package com.hqyj.zdf.controller;

import com.hqyj.zdf.pojo.PageData;
import com.hqyj.zdf.pojo.User;
import com.hqyj.zdf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/getAll")
    public String getAllUser(){
        List<User> all = userService.getAll();
        System.out.println(all);
        return "success";
    }
    @RequestMapping("/getAllByPage")
    public String getAllUserByPage(Integer pageNumber, Integer pageSize, ModelMap modelMap){
        int number;
        int size;
        //如果传递的页码为空
        if(pageNumber==null) {
            number=1;
        }else {
            number=pageNumber;
        }
        if(pageSize==null) {
            size=2;
        }else {
            size=pageSize;
        }
        PageData<User> pageData = userService.getUserByPage(number, size);
        modelMap.put("pageData",pageData);
        //请求转发
        return "success";
    }
}
